<?php
class ArticleAction extends AdminBaseAction {
	protected $dao;
	
	public function _initialize() {
		parent::_initialize();
		$this->assign('module', 'Article');
		$this->dao = M(MODULE_NAME) ? M(MODULE_NAME) : D(MODULE_NAME);
	}
	
	public function index() {
		import('ORG.Util.Page');
        $count = $this->dao->count();    //计算总数
        $p = new Page($count, 5);
        $list = $this->dao->limit($p->firstRow . ',' . $p->listRows)->order('id desc')->select();
        $p->setConfig('header', '条数据');
        $p->setConfig('prev', "<");
        $p->setConfig('next', '>');
        $p->setConfig('first', '<<');
        $p->setConfig('last', '>>');
        $page = $p->show();            //分页的导航条的输出变量
        $this->assign("page", $page);
        $this->assign("list", $list); //数据循环变量
        $this->display();
	}
	
	public function insert() {
		$_POST['create_time'] = time();
		$r = $this->dao->create();
		$id = $this->dao->add();
		if ($id) {
			$this->success('添加成功!');
		} else {
			$this->error('添加失败!');
		}
		$this->redirect('Article/index');
	}
}